package com.srcbox.file.util

/*

class CapIconUtil(val activity: Activity) {

    private var filePath = ""
    private val mapInfoList = ArrayList<HashMap<String, String>>()

    fun capScreen() {
        val mediaProjectionManager =
            activity.getSystemService(Context.MEDIA_PROJECTION_SERVICE) as MediaProjectionManager
        activity.startActivityForResult(
            mediaProjectionManager.createScreenCaptureIntent(),
            1
        )
    }

    fun currentScreen(view: View) {
        if (CapData.rootNode == null) return
        CapData.currentState = CapData.RUNING
        view.visibility = View.GONE
        val screenShotHelper = ScreenShotHelper(
            CapData.activity,
            CapData.resultCode,
            CapData.intentData,
            ScreenShotHelper.OnScreenShotListener { bitmap ->
                CapData.currentState = CapData.OK
                view.visibility = View.VISIBLE
                println("截图成功")
                val packageManager = activity.packageManager
                val applicationInfo =
                    packageManager.getApplicationInfo(CapData.rootNode?.packageName.toString(), 0)
                val appName = packageManager.getApplicationLabel(applicationInfo)
                this.filePath = AppSetting.fileStoragePath + "page/" + appName + "/"
                val file = File(filePath)
                if (!file.exists()) file.mkdirs()

                Thread {
                    foreachNode(CapData.rootNode)
                    mapInfoList.forEach {
                        saveIconFile(it, bitmap)
                    }
                    mapInfoList.clear()
                    bitmap.recycle()
                    activity.runOnUiThread {
                        EggUtil.toast(activity, "抓捕成功，路径：${this.filePath}")
                    }
                }.start()
            })
        screenShotHelper.startScreenShot()
    }

    private fun foreachNode(node: AccessibilityNodeInfo?) {
        node?.let {
            if (CapturedImageConfig.classNames.contains(it.className)) {
                val rect = Rect()
                node.getBoundsInScreen(rect)
                val map = HashMap<String, String>()
                map["state"] = "cut"
                map["package"] = node.packageName.toString()
                map["x"] = rect.left.toString()
                map["y"] = rect.top.toString()
                map["w"] = rect.width().toString()
                map["h"] = rect.height().toString()
                mapInfoList.add(map)
            }
            for (i in 0 until it.childCount) {
                foreachNode(it.getChild(i))
            }
        }
    }

    private fun saveIconFile(map: HashMap<String, String>, bitmap: Bitmap) {
        val bit = EggUtil.cutBitmap(
            bitmap,
            map["x"]!!.toInt(),
            map["y"]!!.toInt(),
            map["w"]!!.toInt(),
            map["h"]!!.toInt()
        ) ?: return
        val randNum = (11111..99999).random()
        EggUtil.saveBitmapFile(
            bit, "$filePath${System.currentTimeMillis()}-$randNum.png"
        )
    }
}*/
